package com.ravi.service;

import com.ravi.dao.AdminUserDAO;
import com.ravi.entity.AdminUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class AdminUserService {

	@Autowired
	private AdminUserDAO adminUserDAO;

	public AdminUser login(AdminUser user) {
		AdminUser userDB = adminUserDAO.findUserById(user.getWorkId());
		if (!ObjectUtils.isEmpty(userDB)) {
			if (userDB.getPassword().equals(user.getPassword())) {
				userDB.setPassword(null);
				return userDB;
			}else {
				throw new RuntimeException("工号或者密码错误！");
			}
		}else {
			throw  new  RuntimeException("工号或者密码错误！");
		}
	}
}
